package ne.analyzer.ui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;

/**
 * 分步骤按钮
 * 
 * @author sunny
 *
 */
public abstract class StepPanel extends Composite {

	public StepPanel(Composite parent, int style, String text, String tips) {
		super(parent, style);
		this.setLayout(new FormLayout());
		boolean hasTip = (tips != null && !tips.equals(""));
		Label sepLabel = new Label(this, SWT.BORDER);
		sepLabel.setText("");
		FormData sepData = new FormData();
		sepData.left = new FormAttachment(0, 0);
		sepData.right = new FormAttachment(0, 2);
		sepData.bottom = new FormAttachment(100, -2);
		sepData.top = new FormAttachment(0, 2);
		sepLabel.setLayoutData(sepData);
		if (hasTip) {
			FormData tipData = new FormData();
			tipData.left = new FormAttachment(sepLabel, 2);
			tipData.right = new FormAttachment(100, -2);
			tipData.bottom = new FormAttachment(100, -2);
			tipData.top = new FormAttachment(100, -42);

			Label tip = new Label(this, SWT.LEFT | SWT.WRAP);
			tip.setText(tips);
			tip.setLayoutData(tipData);

			FormData fd = new FormData();
			fd.left = new FormAttachment(sepLabel, 2);
			fd.right = new FormAttachment(100, -2);
			fd.bottom = new FormAttachment(tip, -2);
			fd.top = new FormAttachment(0, 25);
			Composite content = new Composite(this, SWT.NONE);
			content.setLayoutData(fd);
			Label title = new Label(this, SWT.BOLD | SWT.CENTER | SWT.TOP);
			title.setText(text);
			FormData td = new FormData();
			td.left = new FormAttachment(sepLabel, 2);
			td.right = new FormAttachment(100, -2);
			td.bottom = new FormAttachment(content, -2);
			td.top = new FormAttachment(0, 2);
			title.setLayoutData(td);
			createContent(content);
		} else {
			FormData fd = new FormData();
			fd.left = new FormAttachment(sepLabel, 2);
			fd.right = new FormAttachment(100, -2);
			fd.bottom = new FormAttachment(100, -2);
			fd.top = new FormAttachment(0, 25);
			Composite content = new Composite(this, SWT.NONE);
			content.setLayoutData(fd);
			Label title = new Label(this, SWT.BOLD | SWT.CENTER | SWT.TOP);
			title.setText(text);
			FormData td = new FormData();
			td.left = new FormAttachment(sepLabel, 2);
			td.right = new FormAttachment(100, -2);
			td.bottom = new FormAttachment(content, -2);
			td.top = new FormAttachment(0, 2);
			title.setLayoutData(td);
			createContent(content);
		}

	}

	public abstract Composite createContent(Composite content);
}
